﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum E_Alignment
{ 
    Up,
    Down, 
    Left, 
    Right,
    Center,
    Left_UP,
    Right_UP,
    Left_Down,
    Right_Down,
}

[System.Serializable]
public class ControllerGUIPos
{
    private Rect pos = new Rect(0,0,100,100);
    
    //对齐位置
    public E_Alignment screenAlignment = E_Alignment.Center;
    //控件中心位置
    public E_Alignment controllerAlignment = E_Alignment.Center;
    
    public int width;
    public int height;

    public Vector2 offset;

    Rect centerPos;

    void CalculateCenterPos()
    {
        centerPos = new Rect();
        switch (controllerAlignment)
        {
            case E_Alignment.Up:
                centerPos.x = -width / 2;
                centerPos.y = 0;
                break;
            case E_Alignment.Down:
                centerPos.x = -width / 2;
                centerPos.y = -height;
                break;
            case E_Alignment.Left:
                centerPos.x = 0;
                centerPos.y = -height/2;
                break;
            case E_Alignment.Right:
                centerPos.x = -width;
                centerPos.y = -height / 2;
                break;
            case E_Alignment.Center:
                centerPos.x = -width / 2;
                centerPos.y = -height / 2;
                break;
            case E_Alignment.Left_UP:
                centerPos.x = 0;
                centerPos.y = 0;
                break;
            case E_Alignment.Right_UP:
                centerPos.x = -width;
                centerPos.y = 0;
                break;
            case E_Alignment.Left_Down:
                centerPos.x = 0;
                centerPos.y = -height;
                break;
            case E_Alignment.Right_Down:
                centerPos.x = -width;
                centerPos.y = -height;
                break;
        }
    }

    void CalculatePos()
    {
        switch (screenAlignment)
        {
            case E_Alignment.Up:
                pos.x = Screen.width / 2;
                pos.y = 0;
                break;
            case E_Alignment.Down:
                pos.x = Screen.width / 2;
                pos.y = Screen.height;
                break;
            case E_Alignment.Left:
                pos.x = 0;
                pos.y = Screen.height / 2;
                break;
            case E_Alignment.Right:
                pos.x = Screen.width;
                pos.y = Screen.height / 2;
                break;
            case E_Alignment.Center:
                pos.x = Screen.width / 2;
                pos.y = Screen.height / 2;
                break;
            case E_Alignment.Left_UP:
                pos.x = 0;
                pos.y = 0;
                break;
            case E_Alignment.Right_UP:
                pos.x = Screen.width;
                pos.y = 0;
                break;
            case E_Alignment.Left_Down:
                pos.x = 0;
                pos.y = Screen.height;
                break;
            case E_Alignment.Right_Down:
                pos.x = Screen.width;
                pos.y = Screen.height;
                break;
        }
        pos.x += centerPos.x + offset.x;
        pos.y += centerPos.y + offset.y;
    }

    public Rect Pos
    {
        get
        {
            CalculateCenterPos();
            CalculatePos();
            pos.width = width;
            pos.height = height;
            return pos;
        }
    }


}
